package com.china08.yxyapi.api.manage.tec.teaching.continuedu.mytask;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.continuedu.YxyContinueduUserTaskLessonItem;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.continuedu.YxyContinueduUserTaskLessonItemRepository;

/**
 * 
 * @annotation: 继续教育-课时进度查询
 * @author: yaoguanglin
 */
@CrossOrigin
@RestController
public class YxyMyLessonItemProgressSchController extends YxyApiBaseController {

    @Autowired
    private YxyContinueduUserTaskLessonItemRepository yxyContinueduUserTaskLessonItemRepository;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/continuedu/my/item/progress/sch", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(HttpServletRequest request, HttpServletResponse response,
            @RequestBody(required = false) ReqModel reqModel) {

        YxyContinueduUserTaskLessonItem taskLessonItem = yxyContinueduUserTaskLessonItemRepository
                .findById(reqModel.itemId);
        RespModel model = new RespModel();
        if (taskLessonItem != null) {
            model.itemProgress = taskLessonItem.getCurrentView();
        } else {
            model.itemProgress = 0l;
        }

        return model;
    }

    protected static class ReqModel extends YxyApiReqModel {
        // 课时ID
        public String itemId;

    }

    protected static class RespModel extends YxyApiRespModel {
        // 课程进度
        public Long itemProgress;

    }
}
